#include <stdio.h>
#include <stdlib.h>
#define MAXN 30
typedef struct TreeNode* Tree;
struct TreeNode {
    int data;
    Tree  Left;
    Tree  Right;
};
Tree BuildTree(int inorder[], int preorder[], int N);
void sequence(Tree tr);
Tree swap(Tree T);
int main()
{
    Tree T;
    int inorder[MAXN], preorder[MAXN], N, i;
    scanf("%d", &N);
    for (i = 0; i < N; i++)
        scanf("%d", &inorder[i]);
    for (i = 0; i < N; i++)
        scanf("%d", &preorder[i]);
    T = BuildTree(inorder, preorder, N);
    swap(T);
    sequence(T);
    return 0;
}
void sequence(Tree tr) {
    if (tr)
    {
        Tree b[100];
        b[0] = tr;
        int front = 0;
        int rear = 1;
        while (front < rear)
        {
            if (front) printf(" ");
            printf("%d", b[front]->data);
            if (b[front]->Left)
            {
                b[rear++] = b[front]->Left;

            }
            if (b[front]->Right)
            {
                b[rear++] = b[front]->Right;
            }
            front++;
        }
    }
}
Tree BuildTree(int inorder[], int preorder[], int N) {
    if (N <= 0)
        return NULL;
    int i = 0;
    while (inorder[i] != preorder[0])
        i++;
    Tree tr = (Tree)malloc(sizeof(struct TreeNode));
    tr->data = inorder[i];
    tr->Left = BuildTree(inorder, preorder + 1, i);
    tr->Right = BuildTree(inorder + i + 1, preorder + i + 1, N - i - 1);
    return tr;
}
Tree swap(Tree T)
{
    if (T) {
        T->Left = swap(T->Left);
        T->Right = swap(T->Right);
        Tree tmp;
        tmp = T->Left;
        T->Left = T->Right;
        T->Right = tmp;
    }
    return T;
}